import store from '@/store'
import request from '@/utils/request'

//下架
export function takeDown(params) {
    return request({
        method: 'put',
        url: 'order/takeDownOrder/' + params.item,
        headers: {
            'Authorization': store.state.token,
        },
    })
}
//上架
export function takeUp(params) {
    return request({
        method: 'put',
        url: 'order/takeUpOrder/' + params.item,
        headers: {
            'Authorization': store.state.token,
        },
    })
}

// 添加订单
export function addOrder(params) {
    return request({
        method: 'post',
        url: 'orders/addOrder',
        data: params,
    })
}

// 分页查询所有货源（商品）订单
export function selectGoodsPage() {
    return request({
        method: 'get',
        url: 'orders/hotOrders',
        headers: {
            'Authorization': store.state.token,
        },
    })
}


// 分页查询所有商品（订单）订单
export function selectAllPage(params) {
    //不是搜索，分页返回所有货源
    if (params.keys == null || params.keys == "") {
        return request({
            method: 'get',
            url: 'orders/all',
            params: params,
            headers: {
                'Authorization': store.state.token,
            },
        })
        //是搜索，分页返回搜索货源
    } else {
        return request({
            method: 'get',
            url: 'orders/selectByKeys',
            params: params,
            headers: {
                'Authorization': store.state.token,
            },
        })
    }
}


// 分页查询所有需求订单
export function selectNeedsPage(params) {
    if (params.keys == null || params.keys == "") {
        return request({
            method: 'get',
            url: 'order/needs/' + params.pageNum,
            // params: params,,
            headers: {
                'Authorization': store.state.token,
            },
        })
    } else {
        return request({
            method: 'get',
            url: 'order/searchNeedsByKeys/' + params.keys + '/' + params.pageNum,
            // params: params,,
            headers: {
                'Authorization': store.state.token,
            },
        })
    }
}

//根据id查询订单
export function selectOrderById(params) {
    return request({
        method: 'get',
        url: 'orders/selectOrderById/' + params.orderId,
        headers: {
            'Authorization': store.state.token,
        },
    })
}

//根据id修改订单
export function updateOrderById(params) {
    return request({
        method: 'put',
        url: 'orders/updateOrder',
        data: params.data,
        params: {
            flag: params.flag
        }
    })
}

// 根据id删除订单
export function deleteOrderById(params) {
    return request({
        method: 'delete',
        url: 'orders/deleteOrder/' + params.order_id,
    })
}

//根据用户名+订单类型查询订单
export function selectByUsername(params) {
    return request({
        method: 'get',
        url: 'orders/selectByUsername',
        params: params
    })
}

// //根据种类，用户名查询个人商品模糊查询
// export function selectOrderByKeys(params) {
//     return request({
//         method: 'get',
//         url: 'order/search/' + params.ctype + '/' + params.pageNum,
//         headers: {
//             'Authorization': store.state.token,
//         },
//     })
// }

// 根据登陆用户查询我买的订单
export function selectBuyByUserName() {
    return request({
        method: 'get',
        url: 'carts/selectBuys',
    })
}

// 根据登陆用户查询我买的订单
export function selectOwnByName(params) {
    return request({
        method: 'get',
        url: 'user/' + params.own_name,
        headers: {
            'Authorization': store.state.token,
        },
    })
}

// 根据登录用户查询我卖的订单
export function selectSellByUserName() {
    return request({
        method: 'get',
        url: 'carts/selectSells',
    })
}

// 检索问答接口
export function selectQuestions(params) {
    if (params.keys == null || params.keys == "") {
        return request({
            method: 'get',
            url: `/questions/all`,
            params: params,
        })
    } else {
        return request({
            method: 'get',
            url: `/questions/selectByKeys`,
            params: params,
        })
    }
}

// 检索专家接口
export function selectExpert(params) {
    if (params.keys == null || params.keys == "") {
        return request({
            method: 'get',
            url: `/questions/allExperts`,
            params: params,
        })
    } else {
        return request({
            method: 'get',
            url: `/questions/selectExpertByKeys`,
            params: params,
        })
    }
}
// 问答详情
export function questionDetail(params) {
    return request({
        method: 'get',
        url: `questions/selectQuestionById/${params.id}`,
    })
}
//去提问
export function addQuestion(params) {
    return request({
        method: 'post',
        url: `/questions/addQuestion`,
        data: params
    })
}

//去预约
export function addReserve(params) {
    return request({
        method: 'post',
        url: `/reserves/add`,
        data: params
    })
}

